package graphs

import (
	"power/core/dao/table"
	"power/core/dao/graphdao"
	"power/core/localwrap"
)

var logGraphFields = localwrap.GetLogger().Fork("power/core/service/graphs", "GraphFields")

type GraphFields struct{}

func (s GraphFields) Query(param graphdao.GraphFieldsQueryParam) ([]table.GraphField, int64) {
	logGraphFields.Debug().Func("Query").Interface("param", param).Send()
	d := localwrap.GetRedisedMysql()
	defer d.Close()
	return graphdao.GraphFields{RedisedMysql: d}.Query(param)
}

func (s GraphFields) Get(id int) table.GraphField {
	logGraphFields.Debug().Func("Get").Int("id", id).Send()
	d := localwrap.GetRedisedMysql()
	defer d.Close()
	return graphdao.GraphFields{RedisedMysql: d}.Get(id)
}

func (s GraphFields) Add(param graphdao.GraphFieldsAddParam) table.GraphField {
	logGraphFields.Debug().Func("Add").Interface("param", param).Send()
	d := localwrap.GetRedisedMysql()
	defer d.Close()
	return graphdao.GraphFields{RedisedMysql: d}.Add(param)
}

func (s GraphFields) Update(param graphdao.GraphFieldsUpdateParam) {
	logGraphFields.Debug().Func("Update").Interface("param", param).Send()
	d := localwrap.GetRedisedMysql()
	defer d.Close()
	graphdao.GraphFields{RedisedMysql: d}.Update(param)
}

func (s GraphFields) Delete(id int) {
	logGraphFields.Debug().Func("Delete").Int("id", id).Send()
	d := localwrap.GetRedisedMysql()
	defer d.Close()
	graphdao.GraphFields{RedisedMysql: d}.Delete(id)
}

//GetByGraphIdProtoIdFieldId
func (s GraphFields) GetByGraphIdProtoIdFieldId(graphId int,protoId int,fieldId int) table.GraphField {
	logGraphFields.Debug().Func("GetByGraphIdProtoIdFieldId").Int("graphId", graphId).Int("protoId", protoId).Int("fieldId", fieldId).Send()
	d := localwrap.GetRedisedMysql()
	defer d.Close()
	return graphdao.GraphFields{RedisedMysql: d}.GetByGraphIdProtoIdFieldId(graphId, protoId, fieldId)
}

//ListByProtoId
func (s GraphFields) ListByProtoId(protoId int) []table.GraphField {
	logGraphFields.Debug().Func("ListByProtoId").Int("protoId", protoId).Send()
	d := localwrap.GetRedisedMysql()
	defer d.Close()
	return graphdao.GraphFields{RedisedMysql: d}.ListByProtoId(protoId)
}

//ListByFieldId
func (s GraphFields) ListByFieldId(fieldId int) []table.GraphField {
	logGraphFields.Debug().Func("ListByFieldId").Int("fieldId", fieldId).Send()
	d := localwrap.GetRedisedMysql()
	defer d.Close()
	return graphdao.GraphFields{RedisedMysql: d}.ListByFieldId(fieldId)
}
